<script>
	//$('#nip').focus();
	$(document).ready(function(){
		
		save_data_seleksi<?=$objectid?> = function(){
			rows = $('#dg_add<?=$objectid?>').datagrid('getData');
			//alert(JSON.stringify(rows));
			//return 0;
			
			$.ajax({
			  url: url<?=$objectid?>,
			  method: 'POST',
			  data: {
						id_psb : $('#id_psb<?=$objectid?>').val(),
						id_kelompok : $('#id_kelompok<?=$objectid?>').val(),
						data : rows
					},
			  success : function(result, textStatus){
				//alert(result);
				var response = eval('('+result+')');
				if(response.success){
					$.messager.show({
						title: 'Success',
						msg: 'Data Berhasil Disimpan'
					});
					$('#window<?=$objectid?>').dialog('close');
					$('#dg<?=$objectid?>').datagrid('reload');
				}else{
					ShowMessageError(response.msg);
				}
			  }
			});
		}
		//end saveData
		
		// auto complite
		$('#id_psb<?=$objectid?>').change(function(){
			$('#id_kelompok<?=$objectid?>').load(base_url+'prosedur/get_gelombang_by_psb/'+$('#id_psb<?=$objectid?>').val());
		});
		
		// init grid
		$(function(){
			$('#dg_add<?=$objectid?>').datagrid({
				url:"<?=base_url()?>sd/psb/seleksi/grid_seleksi",
				queryParams: {
					'id_psb' : $('#id_psb<?=$objectid?>').val(),
					'id_kelompok' : $('#id_kelompok<?=$objectid?>').val(),
				}
			});
		});
		
		// filter
		filter_seleksi<?=$objectid?> = function(){
			$('#dg_add<?=$objectid?>').datagrid('load',{
				'id_psb' : $('#id_psb<?=$objectid?>').val(),
				'id_kelompok' : $('#id_kelompok<?=$objectid?>').val(),
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		// custom cell grid
		update_value<?=$objectid?> = function(index, value){
			$('#dg_add<?=$objectid?>').datagrid('updateRow',{index:index, row:{'status':value}});
		}
		
		cell_change_status<?=$objectid?> = function(value,row,index){
			var out="";
			out += '<label style="color:#00F"><input type="radio" name="radio'+index+'" value="1" '+(value==1?'checked="checked"':'')+' onclick="javascript:update_value<?=$objectid?>(\''+index+'\', this.value)" />&nbsp;Lulus</label>';
			out += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
			out += '<label style="color:#F00"><input type="radio" name="radio'+index+'" value="0" '+(value==0?'checked="checked"':'')+' onclick="javascript:update_value<?=$objectid?>(\''+index+'\', this.value)" />&nbsp;Tidak Lulus</label>';
			
			return out;
		}
		
	});
</script>

	<table id="dg_add<?=$objectid?>" title="" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:false,
				pageSize:9000,
				fit:true,
				toolbar:'#toolbar_add<?=$objectid?>',
				onLoadSuccess: function(data){
					ShowGridMessage(this, 'Tidak Terdapat Data');
				},
				">
		<thead>
			<tr>
				<th field="id" width="100" hidden="true"></th>
				<th field="no_pendaftaran" width="130">No. Pendaftaran</th>
				<th field="nama" width="150">Nama Calon Siswa</th>
				<th field="jk" width="50">JK</th>
				<th field="tgl_lahir" width="80">Tgl Lahir</th>
				<th field="uang_sumbangan" width="90" align="right">Sumbangan</th>
				<th field="status" width="200" formatter="cell_change_status<?=$objectid?>">Status</th>
			</tr>
		</thead>
	</table>
	<div id="toolbar_add<?=$objectid?>" style="padding:0px;height:auto">
		<div class="fsearch">
			<div>
				<table width="100%" border="0" cellpadding="3" cellspacing="3">
				  <tr>
					<td width="150px">Proses penerimaan</td>
					<td>: 
						<select name="id_psb" id="id_psb<?=$objectid?>" style="width:230px;">
							<?=$this->mdl_prosedur->option_proses_penerimaan();?>
						</select>
					</td>
				  </tr>
				  <tr>
					<td>Gelombang</td>
					<td>: 
						<select name="id_kelompok" id="id_kelompok<?=$objectid?>" style="width:230px;">
							<?=$this->mdl_prosedur->option_kelompok_penerimaan()?>
						</select>
					</td>
				  </tr>
				  <tr>
					<td>&nbsp;</td>				
					<td>&nbsp;&nbsp;<a href="#" onclick="filter_seleksi<?=$objectid?>()" class="easyui-linkbutton" iconCls="icon-reload" style="width:100px;">Refresh</a></td>
				  </tr>
				</table>
			</div>
		</div>
	</div>



